<template>
  <el-card shadow="never">
    <LTForm
      @submit="submit"
      v-bind="searchFormConfig"
      v-model="formData"
      @resetForm="resetForm"
    />
  </el-card>
</template>

<script setup lang="ts">
import LTForm from "@/components/base-ui/form";
import { ref } from "vue";

const props = defineProps({
  searchFormConfig: {
    type: Object,
    required: true
  }
});

const formItems = props.searchFormConfig?.formItems ?? [];

const formOriginData: any = {};
for (const item of formItems) {
  formOriginData[item.field] = item?.default ?? "";
}
const formData = ref(formOriginData);

const resetForm = () => {
  for (const key in formOriginData) {
    formData.value[`${key}`] = formOriginData[key];
  }
};

const emits = defineEmits(["searchSubmit"]);
const submit = () => emits("searchSubmit", formData.value);
</script>

<style scoped></style>
